package com.xiaoqiang.mybatis.study.spring;

import com.xiaoqiang.mybatis.study.base.Student;
import com.xiaoqiang.mybatis.study.spring.dao.StudentMapper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 小强
 * @since 2019/1/2 19:50
 */
public class MybatisSpringXmlConfigDemo {

    private static ApplicationContext context;

    static {
        context = new ClassPathXmlApplicationContext("spring.xml");
    }

    public static void main(String[] args) {
        new MybatisSpringXmlConfigDemo().insert();
    }

    @Transactional
    public void insert(){
        Student student = new Student();
        student.setName("张三");
        student.setAge(18);
        ((StudentMapper)context.getBean("studentMapper")).insert(student);
        System.out.println(student);
    }

}
